package medium最长回文子串;

import org.testng.annotations.Test;

public class Solution1 {
    public String longestPalindrome(String s) {
        String t = new String();
        String t1 = new String();
        Boolean bool = true;
        if (s.length() ==1)
            return s;
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j < s.length(); j++) {
                if (s.charAt(i) == s.charAt(j)){
                    t = s.substring(i,j+1);
                    for (int k = 0,q = t.length()-1; k<q ; k++,q--) {
                        if (t.charAt(k) == t.charAt(q))
                            continue;
                        else {
                            bool = false;
                            break;
                        }
                    }
                    if (bool == true && t1.length()<t.length()){
                        t1 = t;
                    }
                    else
                        bool = true;
                }
            }
        }
        if (t1.length() == 0)
            t1 = s.substring(0,1);
        return t1;
    }

    @Test
    public void test(){
        String s = "aacabdkacaa";
        System.out.println(longestPalindrome(s));
    }
}
